'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:AdministratorAdminZjzczxCtrl
 * @description
 * # AdministratorAdminZjzczxCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('AdministratorAdminZjzczxCtrl', function ($scope, DataService, $rootScope, openApi, Util, $location, $routeParams, FormSubmit) {
        var id = $scope.process_id = $routeParams.id
        $scope.chooseinfo = function () {
            var relModuleObj = {
                name: "AdministratorAdminZjzczxCtrl",
                selectTab: "select_certificate_by_transfer",
                selectTabContent: "选择证件"
            };
            // 清掉关联的编号
            var params = $scope.param;
            Util.savaParamForReview(params, id);
            Util.savaDataforsearch(relModuleObj);
            $location.path("finance/choosepeople")
        };
        // 底部关联模块类型选框添加
        $scope.willReturnList = [{
            key: "否",
            value: 1
        }, {
            key: "是",
            value: 2
        }];
        $scope.dealTypeList = [{
            key: "转出",
            value: 1
        }, {
            key: "注销",
            value: 2
        }];
        $scope.dealTypechange = function () {
            if ($scope.param.dealType == 2) {
                $scope.param.willReturn = 1
            }
        }
        $scope.submit = function (operationId) {

            // 底部类型end
            var options = {};
            // 流程id
            options.id = id;
            // 根据operationId判断是草稿还是提交
            options.operationId = operationId;
            options.urlParam = openApi.certificateTransfer;
            options.param = angular.copy($scope.param, {});
            FormSubmit.submit(options,$scope);
        };
        $scope.validate = function () {
            if (!$scope.param.certificateId) {
                Util.Toast("请选择证件编号");
                return;
            }
            if (!$scope.param.transferTarger && $scope.param.dealType == 1) {
                Util.Toast("请填写接收单位");
                return;
            }
            if ($scope.param.willReturn == 2 && $scope.param.dealType == 1) {
                if (!$scope.param.returnDate) {
                    Util.Toast("请选择预计转回日期");
                    return;
                }
            }
            if (!$scope.param.willReturn && $scope.param.dealType == 1) {
                Util.Toast("请选择是否转回");
                return;
            }
            if (!$scope.param.dealType) {
                Util.Toast("请选择办理类型");
                return;
            }
            if (!$scope.validation.passvalidation) {
                Util.Toast($scope.validation.tip);
                return;
            }
            return true;
        }
        var init = function () {
            // 获取回显的详细信息
            Util.getDetailData(id, function (data) {
                $scope.param = data;
                $scope.param.dealType=$scope.param.dealType||1;
                $scope.param.willReturn=$scope.param.willReturn||1;
            });
        };
        // 初始化
        init();
    });